<template>
  <div class="home-module__advert container" :class="`col-${datas.number}`">
    <div
      v-for="(item, index) in datas.list"
      :key="index"
      class="item hvr-float"
      @click="clickAdvert(item)"
    >
      <edu-image :src="item.url" fit="cover" lazy></edu-image>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Advert',
  props: {
    datas: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {}
  },
  methods: {
    clickAdvert(item) {
      if (item.type == 1 && item.course_id) {
        this.$router.push({
          path: `/course/${item.course_id}`
        })
      } else if (item.type == 2 && item.href) {
        window.open(item.href, '_blank')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
@import '@/styles/hover.scss';
.home-module__advert {
  margin-bottom: 30px;
  display: grid;
  &.col-2 {
    grid-template-columns: repeat(2, minmax(0px, 1fr));
    gap: 0 40px;
  }
  &.col-3 {
    grid-template-columns: repeat(3, minmax(0px, 1fr));
    gap: 0 20px;
  }
  &.col-4 {
    grid-template-columns: repeat(4, minmax(0px, 1fr));
    gap: 0 20px;
  }
  .item {
    grid-column: span 1 / span 1;
    height: 0;
    padding-top: 130px;
    position: relative;
    cursor: pointer;
    .el-image {
      width: 100%;
      height: 100%;
      position: absolute;
      left: 0;
      top: 0;
    }
  }
}
</style>
